/**
 * Created by CSJ11 on 2017/7/3.
 */
'use strict';
angular.module('app')
    .controller('channelController', [ '$rootScope', '$scope', '$http', '$state','$timeout',
        function($rootScope, $scope, $http, $state, $timeout) {
            $scope.title = '平台基本信息';
            $scope.searchParams = { };
            $scope.loading = false;
            $scope.url="https://ifci.lincomb.com";//本地也显示图片
            $scope.param={};
            $scope.search = function () {
                $scope.loading = true;
                $.ajax({
                    url : $scope.app.project_name+'/thirdPlatform/channel/list',
                    data: $scope.searchParams
                }).then(function(result) {
                    console.log(result);
                    $scope.loading = false;
                    if (result.httpCode == 200) {

                        $scope.pageInfo = result.data;

                    } else {
                        $scope.msg = result.msg;
                    }
                    $scope.$apply();
                });
            }



            $scope.searchRe = function () {
                $scope.loading = true;
                $scope.searchParams.pageNum = 1;
                $.ajax({
                    url : $scope.app.project_name+'/thirdPlatform/channel/list',
                    data: $scope.searchParams
                }).then(function(result) {

                    $scope.loading = false;
                    if (result.httpCode == 200) {
                        $scope.pageInfo = result.data;
                        $(".editSortBtn").show();
                        $(".saveSortBtn").hide();
                    } else {
                        $scope.msg = result.msg;
                    }
                    $scope.$apply();
                });
            }

            $scope.search();

            $scope.clearSearch = function() {

                $scope.searchParams= { };
                $scope.search();
                $(".editSortBtn").show();
                $(".saveSortBtn").hide();
            }



            // 翻页
            $scope.pagination = function (pageNo) {
                $scope.searchParams.pageNum=pageNo;
                $scope.search();
            };


            // 删除轮播图
            $scope.deleteById=function (id,enable) {
                var msg = '';
                if (enable == 'Y') {
                    msg = '启用';
                }

                if (enable == 'N') {
                    msg = '禁用';
                }
                $scope.alertModel({
                    text:'是否'+msg+"?",
                    btnCancel:true,
                    resCode:"10000"
                }).then(function(){
                    $.ajax({
                        url : $scope.app.project_name+'/thirdPlatform/channel/deleteById',
                        data: {id:id,"enable":enable}
                    }).then(function(result) {
                        $scope.loading = false;
                        $scope.alertModal({"content":"操作成功"});
                        if (result.httpCode != 200) {
                            $scope.alertModal(result.msg);
                        }
                        $scope.search();
                    });

                })

            }

            $scope.icon = [];
            $scope.preview = function(icon){
                if (icon != null && icon != '') {
                    $scope.icon =  icon.split('|');
                }
                $scope.firstApply = true;
            }

            $scope.defaultIcon = [];
            $scope.preview1 = function(defaultIcon){
                if (defaultIcon != null && defaultIcon != '') {
                    $scope.defaultIcon =  defaultIcon.split('|');
                }
                $scope.firstApply1 = true;
            }


            // 鼠标移入的动作
            $scope.channelDesc = [];
            $scope.toSee = function(channelDesc){
                var showDiv = document.getElementById('showDiv');
                showDiv.style.left = event.clientX;
                showDiv.style.top = event.clientY;
                showDiv.style.display = 'block';
                showDiv.innerHTML = channelDesc;
            }
            // 鼠标移出的动作
            $scope.outHide = function(){
                var showDiv = document.getElementById('showDiv');
                showDiv.style.display = 'none';
                showDiv.innerHTML = '';
            }

        } ]);